/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rad.Java.MotelPlus.List;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import rad.Java.Common.Class.DefaultList;
import rad.Java.Common.Class.IList;
import rad.Java.Common.DB.GenerateSql;
import rad.Java.MotelPlus.Class.Block;

/**
 *
 * @author rogerio
 */
public class Blocks extends DefaultList implements IList{
           
    public Blocks(){
        _gsql.setTable("block");
    }

    // <editor-fold defaultstate="collapsed" desc="Declaration of functions">
        public boolean fillList() {
            _gsql.prepare();
            _gsql.setCommandType(GenerateSql.CommandType.CMD_SELECT);
            _gsql.setValue("","*");

            return mountList();
        }

        public Block get(int index){
            return (Block) _items.get(index);
        }

        private boolean mountList(){
            try {
                if (!_gsql.execute(false)) {
                    return false;
                }
                clear();
                while (_gsql.next()) {
                    Block block = new Block();
                    block.get(_gsql.getResultSet());
                    _items.add(block);
                }
                return true;
            }
            catch (SQLException ex) {
                Logger.getLogger(Blocks.class.getName()).log(Level.SEVERE, null, ex);
                return false;
            }
        }
        
    // </editor-fold>
}
